<style scoped>
  .expand-row{
    margin-bottom: 16px;
  }
  .lyx-table-btn{
    margin-right: 5px;
    margin-bottom: 2px;
  }
  .w95 {
    width: 95%;
  }
  Col.xreuired before {
    content: '* ';
    color: red;
  }
  .title-size {
    font-weight: bold;
    font-size: 1rem;
  }
  .red {
    color: #FF0000;
    display: inline-block;
  }
  .ivu-form-item-content {
    position: relative;
    line-height: 32px;
    font-size: 12px;
    display: flex;
  }
</style>
<template>
  <div>
      <Form label-position="right" :label-width="100" style="position: relative;" :model="formDate">
      <Row class="mb20">
        <Col span="14" class="ivu-form-item-label title-size">沈阳市公共租赁住房(申请)审批表（城镇）</Col>
      </Row>
<!--      <Row class="mb20">-->
<!--        <Col span="3" offset="1" class="ivu-form-item-label">编号</Col>-->
<!--        <Col span="3" offset="15" class="ivu-form-item-label">单位：平方米,人,员</Col>-->
<!--      </Row>-->
        <Row class="mb20">
          <Col span="3" class="ivu-form-item-label">户口所在地址：</Col>
          <Col span="4" class="ivu-form-item-content" style="padding-right: 5px">
            <Select v-model="formDate.toSection" @on-change="bb">
              <Option v-for="item in sectionList" :value="item.id" :key="item.id">{{ item.title }}</Option>
            </Select>
          </Col>
          <Col span="4" class="ivu-form-item-content" style="padding-right: 5px">
            <Select v-model="formDate.toStreet" @on-change="cc">
              <Option v-for="item in sectionListb" :value="item.id" :key="item.id">{{ item.title }}</Option>
            </Select>
          </Col>
          <Col span="4" class="ivu-form-item-content" style="padding-right: 5px">
            <Select v-model="selectData">
              <Option v-for="item in sectionListc" :value="JSON.stringify(item)" :key="item.id">{{ item.title }}</Option>
            </Select>
          </Col>
        </Row>
      <Row class="mb20">
        <Col span="3" class="ivu-form-item-label">姓名：</Col>
        <Col span="5" class="ivu-form-item-content">
          <Input v-model="formDate.applyPerson"></Input>
          <span class="red">*</span>
        </Col>
        <Col span="3" class="ivu-form-item-label">性别：</Col>
        <Col span="5" class="ivu-form-item-content">
          <Select v-model="formDate.gender" style="width:200px">
            <Option :value=item.value v-for="item in genderData" :key="item.value">{{item.label}}</Option>
          </Select>
          <span class="red">*</span>
        </Col>
        <Col span="3" class="ivu-form-item-label">身份证号码：</Col>
        <Col span="5" class="ivu-form-item-content">
          <Input v-model="formDate.applyIdCard" ></Input>
          <span class="red">*</span>
        </Col>
      </Row>
      <Row class="mb20">
        <Col span="3" class="ivu-form-item-label">婚姻状况：</Col>
        <Col span="5" class="ivu-form-item-content">
          <RadioGroup v-model="formDate.maritalStatus">
            <Radio :label="item.value" v-for=" item in maritalStatusData" :vlaue="item.value" :key="item.value" >{{item.label}}</Radio>
<!--            <Radio label="1">已婚</Radio>-->
          </RadioGroup>
          <span class="red">*</span>
        </Col>
        <Col span="3" class="ivu-form-item-label">联系电话：</Col>
        <Col span="5" class="ivu-form-item-content">
          <Input v-model="formDate.phone" ></Input>
          <span class="red">*</span>
        </Col>
      </Row>
      <Row class="mb20">
        <Col span="3" class="ivu-form-item-label">工作单位：</Col>
        <Col span="5" class="ivu-form-item-content">
          <Input v-model="formDate.company" ></Input>
          <span class="red">*</span>
        </Col>
        <Col span="3" class="ivu-form-item-label">单位地址：</Col>
        <Col span="5" class="ivu-form-item-content">
          <Input v-model="formDate.companyAddress" ></Input>
          <span class="red">*</span>
        </Col>
      </Row>
      <Row class="mb20">
        <Col span="3" class="ivu-form-item-label">单位性质：</Col>
        <Col span="12" class="ivu-form-item-content">
          <RadioGroup v-model="formDate.gzxz">
            <Radio :label="item.value" v-for=" item in gzxzData" :vlaue="item.value" :key="item.value">{{item.label}}</Radio>
          </RadioGroup>
          <span class="red">*</span>
        </Col>
      </Row>
      <Row class="mb20">
        <Col span="3" class="ivu-form-item-label">申请人类型：</Col>
        <Col span="19" class="ivu-form-item-content">
          <div style="width: 100%;float: left">
            <CheckboxGroup  v-model="personTypeArr"  v-for="(item,index) in personType" v-bind:key="index">
              <Checkbox :label="item.personTypeCode"  style="width: max-content;float: left">{{item.personTypeName}}</Checkbox>
            </CheckboxGroup>
            <span class="red">*</span>
          </div>
        </Col>
      </Row>
      <Row class="mb20">
        <Col span="3" class="ivu-form-item-label">户籍具体地址：</Col>
        <Col span="7" class="ivu-form-item-content">
          <Input v-model="formDate.lawAddress" ></Input>
          <span class="red">*</span>
        </Col>
      </Row>
      <Row class="mb20">
        <Col span="3" class="ivu-form-item-label">申请保障方式：</Col>
        <Col span="4" class="ivu-form-item-content">
          <CheckboxGroup v-model="formDate.applyEnsureTypes_list">
            <Checkbox label="0">实物房源</Checkbox>
            <Checkbox label="1">租赁补贴</Checkbox>
          </CheckboxGroup>
        </Col>
        <Col span="3" class="ivu-form-item-label">可单选,可全选
          <span class="red">*</span>
        </Col>
      </Row>
      <Row class="mb20">
        <Col span="13" class="ivu-form-item-label" style="font-weight: 500">申请人家庭收入情况</Col>
      </Row>
        <Row class="mb20">
          <Col span="22" offset="1">
            <Table  border stripe :columns="columns1" :data="tempData.personList" id="table">
              <template slot-scope="{ row }" slot="bz_relation">
                <Select v-model="row.bz_relation" transfer="">
                  <Option v-for="(item, key) in bz_relation_list" :value="item.value" :key="key">{{ item.label }}</Option>
                </Select>
              </template>
              <template slot-scope="{ row }" slot="bz_name">
                <Input v-model="row.bz_name"></Input>
              </template>
              <template slot-scope="{ row }" slot="bz_idcard">
                <Input v-model="row.bz_idcard"></Input>
              </template>
              <template slot-scope="{ row }" slot="bz_companyName">
                <Input v-model="row.bz_companyName"></Input>
              </template>
              <template slot-scope="{ row }" slot="bz_kzpnsr">
                <Input v-model="row.bz_kzpnsr"></Input>
              </template>
            </Table>
          </Col>
        </Row>
        <Row class="mb20">
          <Col span="3" class="ivu-form-item-label">家庭人均月收入：</Col>
          <Col span="5" class="ivu-form-item-content">
            <Input v-model="formDate.personAssets"></Input>
          </Col>
          <Col span="1" class="ivu-form-item-label">元</Col>
          <Col span="4" class="ivu-form-item-label">家庭成员年收入合计：</Col>
          <Col span="5" class="ivu-form-item-content">
            <Input v-model="srhj" ></Input>
          </Col>
          <Col span="1" class="ivu-form-item-label">元</Col>
        </Row>
        <Row class="mb20">
          <Col span="6" class="ivu-form-item-label">家庭收入认定意见</Col>
          <Col span="2" class="ivu-form-item-content">
            <Checkbox v-model="formDate.agree">同意</Checkbox>
            <span class="red">*</span>
          </Col>
          <Col span="3" class="ivu-form-item-label"> 经办人：</Col>
          <Col span="4" class="ivu-form-item-content">
            <Input v-model="formDate.familyMoneyHandler" ></Input>
            <span class="red">*</span>
          </Col>
          <Col span="3" class="ivu-form-item-label"> 认定日期：</Col>
          <Col span="5" class="ivu-form-item-content">
            <DatePicker type="date"   v-model="formDate.familyMoneyDate"  style="width: 200px"></DatePicker>
            <span class="red">*</span>
          </Col>
        </Row>
        <Row class="mb20">
          <Col span="13" class="ivu-form-item-label" style="font-weight: 500">家庭成员住房情况</Col>
        </Row>
        <Row class="mb20">
          <Col span="22" offset="1">
            <Table border :columns="columns2" :data="tempData.houseList" id="aaa">
              <template slot-scope="{ row }" slot="holder">
                <Input v-model="row.holder" style="width: 95%"></Input>
              </template>
              <template slot-scope="{ row }" slot="address">
                <Input v-model="row.address" style="width: 95%"></Input>
              </template>
              <template slot-scope="{ row }" slot="buildArea">
                <Input v-model="row.buildArea" style="width: 95%" v-on:input="change()"></Input>
              </template>
              <template slot-scope="{ row }" slot="ownerType">
                <Select v-model="row.ownerType" style="width:200px">
                  <Option value="承租公房">承租公房</Option>
                  <Option value="私有房产">私有房产</Option>
                </Select>
              </template>
            </Table>
          </Col>
        </Row>
        <Row class="mb20">
          <Col span="6" class="ivu-form-item-label">家庭人均建筑面积</Col>
          <Col span="4" class="ivu-form-item-content">
            <Input v-model="rjmj"></Input>
          </Col>
          <Col span="1" class="ivu-form-item-label">㎡</Col>
          <Col span="3" class="ivu-form-item-content">
            <Button @click="checkAve()">点击计算家庭人均建筑面积</Button>
          </Col>
        </Row>
        <Row class="mb20">
          <Col span="6" class="ivu-form-item-label">社区经办人</Col>
          <Col span="4" class="ivu-form-item-content">
            <Input v-model="formDate.committeeHandler"></Input>
            <span class="red">*</span>
          </Col>
          <Col span="6" class="ivu-form-item-label">社区负责人</Col>
          <Col span="4" class="ivu-form-item-content">
            <Input v-model="formDate.committeePrincipal"></Input>
            <span class="red">*</span>
          </Col>
        </Row>
        <Row class="mb20">
          <Col span="6" class="ivu-form-item-label">受理时间</Col>
          <Col span="4">
            <DatePicker type="date" v-model="formDate.acceptDate" style="width: 200px"></DatePicker>
          </Col>
        </Row>
        <Row class="">
          <Col span="4" offset="10" class="ivu-form-item-label">注：用*标记的项为必填项</Col>
        </Row>
        <Row class="mb20">
          <Col span="13" class="ivu-form-item-label">
            <Button @click="save()">提交</Button>
          </Col>
        </Row>
    </Form>
  </div>
</template>
<script>
import { getSQCodeFc, getMailLevelList, date2str } from '@/api/eventlist'
import { ensureApply } from '@/api/houseproperty'
export default {
  name: 'Form2',
  data () {
    return {
      hj_address: '',
      personTypeArr: [],
      ruleData: {},
      selectData: '',
      sectionList: [],
      sectionListb: [],
      sectionListc: [],
      a: 0, // 家庭人均月收入
      b: 0, // 家庭成员年收入合计
      genderData: [
        {
          value: 0,
          label: '男'
        },
        {
          value: 1,
          label: '女'
        }
      ],
      maritalStatusData: [
        {
          value: 0,
          label: '单身'
        },
        {
          value: 1,
          label: '已婚'
        }
      ],
      gzxzData: [
        {
          value: 0,
          label: '企业'
        },
        {
          value: 1,
          label: '机关事业单位'
        },
        {
          value: 2,
          label: '个体工商户'
        },
        {
          value: 3,
          label: '离退休'
        },
        {
          value: 4,
          label: '其它'
        }
      ],
      personDataList: [],
      personType: [],
      ab: '',
      proposerLawSectionCodeList: [
        {
          value: '210102',
          label: '210102'

        }
      ],
      rjmjArr: [],
      rjysrArr: [],
      rjmj: this.itemInfoObj.buildAveArea || '0.0000',
      rjysr: 0,
      srhj: 0,
      tempIndex: '0',
      totalArea: 0,
      paramsArr: [],
      list: [],
      /* sectionList: [],
      streetList: [],
      committeesList: [], */
      relationList: [
        { label: '本人', value: '0' },
        { label: '之妻', value: '1' },
        { label: '之子', value: '2' },
        { label: '之女', value: '3' },
        { label: '之父', value: '4' },
        { label: '之母', value: '5' },
        { label: '之夫', value: '6' },
        { label: '之儿媳', value: '7' },
        { label: '之女婿', value: '8' },
        { label: '之孙子', value: '9' },
        { label: '之孙女', value: '10' },
        { label: '其他亲属', value: '11' }
      ],
      person_type_list: [],
      bz_relation_list: [
        { label: '本人', value: 0 },
        { label: '之妻', value: 1 },
        { label: '之子', value: 2 },
        { label: '之女', value: 3 },
        { label: '之父', value: 4 },
        { label: '之母', value: 5 },
        { label: '之夫', value: 6 },
        { label: '之儿媳', value: 7 },
        { label: '之女婿', value: 8 },
        { label: '之孙子', value: 9 },
        { label: '之孙女', value: 10 },
        { label: '其他亲属', value: 11 }
      ],
      ownerTypeList: ['承租公房', '私有房产'],
      columns1: [
        {
          title: '与申请人关系',
          key: 'bz_relation',
          render: (h, params) => {
            return h('Select', {
              props: {
                value: params.row.bz_relation, // 获取选择的下拉框的值
                transfer: true
              },
              on: {
                'on-change': event => {
                  this.tempData.personList[params.index].bz_relation = event
                }

              }
            }, this.bz_relation_list.map((item) => { // this.productTypeList下拉框里的data
              return h('Option', { // 下拉框的值
                props: {
                  value: item.value
                }
              }, item.label)
            }))
          }
        },
        {
          title: '姓名',
          key: 'bz_name',
          render: (h, params) => {
            let temp = []
            temp.push(h('Input', {
              props: {
                value: params.row.bz_name,
                autosize: true
              },
              on: {
                'on-blur': (event) => {
                  this.tempData.personList[params.index].bz_name = event.target.value
                }
              }
            }))
            return h('div', temp)
          }
        },
        {
          title: '身份证号',
          key: 'bz_idcard',
          render: (h, params) => {
            let temp = []
            temp.push(h('Input', {
              props: {
                value: params.row.bz_idcard,
                autosize: true
              },
              on: {
                'on-blur': (event) => {
                  this.tempData.personList[params.index].bz_idcard = event.target.value
                }
              }
            }))
            return h('div', temp)
          }
        },
        {
          title: '工作单位',
          key: 'bz_companyName',
          render: (h, params) => {
            let temp = []
            temp.push(h('Input', {
              props: {
                value: params.row.bz_companyName,
                autosize: true
              },
              on: {
                'on-blur': (event) => {
                  console.log('!@##!@#!@')
                  // this.formDate.personList[params.index]['bz_companyName'] = event.target.value
                  this.tempData.personList[params.index].bz_companyName = event.target.value
                }
              }
            }))
            return h('div', temp)
          }
        },
        {
          title: '可支配年收入',
          key: 'bz_kzpnsr',
          render: (h, params) => {
            let temp = []
            temp.push(h('Input', {
              props: {
                value: params.row.bz_kzpnsr,
                autosize: true
              },
              on: {
                'on-blur': (event) => {
                  this.tempData.personList[params.index].bz_kzpnsr = event.target.value
                  if (this.rjysrArr[params.index] === 'undefined') {
                    this.rjysrArr.push(event.target.value)
                  } else {
                    this.rjysrArr[params.index] = event.target.value
                  }
                  console.log(this.rjysrArr, 'this.rjysrArr')
                  var total = 0
                  for (var i = 0; i < this.rjysrArr.length; i++) {
                    if (this.rjysrArr[i] === '') {
                      this.rjysrArr.splice(i, i + 1)
                    } else {
                      total = total + parseInt(this.rjysrArr[i])
                    }
                  }
                  console.log(total)
                  this.srhj = total
                  this.formDate.yearAssets = this.srhj.toFixed(2)
                  var tempMoney = (total / (params.index + 1)).toFixed(2)
                  this.formDate.personAssets = (tempMoney / 12).toFixed(2)
                  console.log(this.formDate.personAssets)
                }
              }
            }))
            return h('div', temp)
          }
        }
      ],
      columns2: [
        {
          title: '产权人或承租人',
          key: 'holder',
          render: (h, params) => {
            let temp = []
            temp.push(h('Input', {
              props: {
                value: params.row.holder,
                autosize: true
              },
              on: {
                'on-blur': (event) => {
                  this.tempData.houseList[params.index].holder = event.target.value
                }
              }
            }))
            return h('div', temp)
          }
        },
        {
          title: '房屋坐落',
          key: 'address',
          render: (h, params) => {
            let temp = []
            temp.push(h('Input', {
              props: {
                value: params.row.address,
                autosize: true
              },
              on: {
                'on-blur': (event) => {
                  this.tempData.houseList[params.index].address = event.target.value
                }
              }
            }))
            return h('div', temp)
          }
        },
        {
          title: '建筑面积',
          key: 'buildArea',
          render: (h, params) => {
            let temp = []
            temp.push(h('Input', {
              props: {
                value: params.row.buildArea,
                autosize: true
              },
              on: {
                'on-blur': (event) => {
                  this.tempData.houseList[params.index].buildArea = event.target.value
                  if (this.rjmjArr[params.index] === 'undefined') {
                    this.rjmjArr.push(event.target.value)
                  } else {
                    this.rjmjArr[params.index] = event.target.value
                  }
                  console.log(this.rjmjArr, 'this.rjmjArr')
                  var total = 0
                  for (var i = 0; i < this.rjmjArr.length; i++) {
                    if (this.rjmjArr[i] === '') {
                      this.rjmjArr.splice(i, i + 1)
                    } else {
                      total = total + parseInt(this.rjmjArr[i])
                    }
                  }
                  console.log(total)
                  this.rjmj = (total / (params.index + 1)).toFixed(4)
                  this.formDate.buildAveArea = this.rjmj
                  console.log(this.formDate.buildAveArea)
                },
                'on-change': (event) => {
                }
              }
            }))
            return h('div', temp)
          }
        },
        {
          title: '住房性质',
          key: 'ownerType',
          render: (h, params) => {
            return h('Select', {
              props: {
                value: params.row.ownerType, // 获取选择的下拉框的值
                transfer: true
              },
              on: {
                'on-change': event => {
                  this.tempData.houseList[params.index].ownerType = event
                }
              }
            }, this.ownerTypeList.map((item) => { // this.productTypeList下拉框里的data
              return h('Option', { // 下拉框的值
                props: {
                  value: item
                }
              }, item)
            }))
          }
        }
      ],
      data: []
    }
  },
  props: {
    aacode: String,
    formDate: Object,
    applyEnsureTypes_list: Array,
    personTypeList: Array,
    tempData: Object,
    itemInfoObj: Object
  },
  mounted () {
    this.formDate.personList = []
    if (this.itemInfoObj.toSection || this.itemInfoObj.toStreet) {
      this.formDate.toSection = this.itemInfoObj.toSection
      this.formDate.toStreet = this.itemInfoObj.toStreet
    }
    this.bb()
    this.cc(this.itemInfoObj.sqCompanyCode)
    this.srhj = this.itemInfoObj.yearAssets
    this.getPermanentAddress()
    if (this.itemInfoObj.sqCompanyCode) {
      var param = { company_code: this.itemInfoObj.sqCompanyCode }
      getSQCodeFc(param).then(res => {
        if (res.data.errcode === 0) {
          this.proposerRule(res.data.data.qu_code)
        } else {
          this.$Notice.error({ title: '失败', desc: res.data.errmsg })
        }
      })
    }
    if (this.formDate.personTypes) {
      this.personTypeArr = this.formDate.personTypes.join(',')
    }
  },
  watch: {
    selectData (item, olditem) {
      this.formDate.sqCompanyCode = JSON.parse(item).company_code
      var param = { company_code: JSON.parse(item).company_code }
      getSQCodeFc(param).then(res => {
        if (res.data.errcode === 0) {
          this.formDate.lawCommitteesCode = res.data.data.shequ_code
          this.proposerRule(res.data.data.qu_code)
        } else {
          this.$Notice.error({ title: '失败', desc: res.data.errmsg })
        }
      })
    }
  },
  methods: {
    bb () {
      let param = { id: this.formDate.toSection }
      getMailLevelList(param).then(res => {
        if (res.data.errcode === 0) {
          this.sectionListb = res.data.data
          console.log(this.sectionListb)
        } else {
          this.$Notice.error({ title: '失败', desc: res.data.errmsg })
        }
      })
    },
    cc (company_code) {
      let param = { id: this.formDate.toStreet }
      getMailLevelList(param).then(res => {
        if (res.data.errcode === 0) {
          this.sectionListc = res.data.data
          for (var i = 0; i < this.sectionListc.length; i++) {
            if (company_code === this.sectionListc[i].company_code) {
              this.selectData = JSON.stringify(this.sectionListc[i])
            }
          }
        } else {
          this.$Notice.error({ title: '失败', desc: res.data.errmsg })
        }
      })
    },
    getPermanentAddress () {
      getMailLevelList().then(res => {
        if (res.data.errcode === 0) {
          /* res.data.data.foreach() */
          this.sectionList = res.data.data
        } else {
          this.$Notice.error({ title: '失败', desc: res.data.errmsg })
        }
      })
    },
    getPersonType () {
      this.formDate.personTypes = this.personTypeArr.join(',')
    },
    getGender (IDCard) {
      if (parseInt(IDCard.substr(16, 1)) % 2 === 1) {
        return 0
      } else {
        return 1
      }
    },
    ss () {
      let data = this.formDate.applyEnsureTypes_list
      for (let i = 0; i < data.length; i++) {
        if (data.length === 2) {
          this.formDate.applyEnsureTypes = 2
          return false
        } else if (data[i] === '0') {
          this.formDate.applyEnsureTypes = 0
        } else if (data[i] === '1') {
          this.formDate.applyEnsureTypes = 1
        }
      }
    },
    save () {
      this.ss()
      this.formDate.buildAveArea = this.rjmj
      let age = this.getAge(this.formDate.applyIdCard)
      if (!this.formDate.applyPerson) {
        this.$Notice.error({ title: '请填写申请人姓名', desc: '' })
        return false
      } else if (this.formDate.gender === undefined) {
        this.$Notice.error({ title: '请填写申请人性别', desc: '' })
        return false
      } else if (this.formDate.applyIdCard === undefined) {
        this.$Notice.error({ title: '请填写申请人身份证号码', desc: '' })
        return false
      } else if (this.formDate.maritalStatus === undefined) {
        this.$Notice.error({ title: '请选择申请人婚姻状况', desc: '' })
        return false
      } else if (!this.formDate.phone) {
        this.$Notice.error({ title: '请填写申请人联系电话', desc: '' })
        return false
      } else if (!this.formDate.company) {
        this.$Notice.error({ title: '请填写申请人工作单位', desc: '' })
        return false
      } else if (!this.formDate.companyAddress) {
        this.$Notice.error({ title: '请填写申请人单位地址', desc: '' })
        return false
      } else if (this.formDate.gzxz === undefined) {
        this.$Notice.error({ title: '请选择申请人单位性质', desc: '' })
        return false
      } else if (!this.formDate.personAssets) {
        this.$Notice.error({ title: '请填写家庭人均可支配月收入', desc: '' })
        return false
      } else if (!this.formDate.yearAssets) {
        this.$Notice.error({ title: '家庭可支配年收入不能为空', desc: '' })
        return false
      } else if (!this.formDate.familyMoneyHandler) {
        this.$Notice.error({ title: '请填写经办人', desc: '' })
        return false
      } else if (!this.formDate.familyMoneyDate) {
        this.$Notice.error({ title: '请填写家庭收入认定日期', desc: '' })
        return false
      } else if (!this.formDate.agree) {
        this.$Notice.error({ title: '请选择申请人家庭收入认定意见', desc: '' })
        return false
      } else if (!this.formDate.lawAddress) {
        this.$Notice.error({ title: '户籍地址不能为空', desc: '' })
        return false
      } else if (!this.formDate.lawCommitteesCode) {
        this.$Notice.error({ title: '户籍所在社区code不能为空', desc: '' })
        return false
      } else if (!this.formDate.committeeHandler) {
        this.$Notice.error({ title: '请填写申请地社区经办人', desc: '' })
        return false
      } else if (!this.formDate.committeePrincipal) {
        this.$Notice.error({ title: '请填写申请地社区负责人', desc: '' })
        return false
      } else if (!this.formDate.acceptDate) {
        this.$Notice.error({ title: '请选择受理时间', desc: '' })
        return false
      }
      // 所选性别与身份证是否符合
      if (this.formDate.gender !== this.getGender(this.formDate.applyIdCard)) {
        this.$Modal.error({
          title: '数据保存失败',
          content: '所选性别与身份证不符'
        })
        return
      }
      this.formDate.personList = [] // 人员信息
      for (var j = 0; j < this.tempData.personList.length; j++) {
        if (this.tempData.personList[j].bz_relation !== '') {
          this.formDate.personList.push(this.tempData.personList[j])
        }
      }
      if (this.formDate.company !== this.formDate.personList[0].bz_companyName) {
        this.$Modal.error({
          title: '数据保存失败',
          content: '家庭成员中主申请人工作单位不符'
        })
        return
      }
      this.formDate.houseList = [] // 房屋信息
      for (var k = 0; k < this.tempData.houseList.length; k++) {
        if (this.tempData.houseList[k].holder !== '') {
          this.formDate.houseList.push(this.tempData.houseList[k])
        }
      }
      this.getPersonType()
      for (let i = 0; i < this.personTypeArr.length; i++) {
        if (this.personTypeArr[i] === 'b' || this.personTypeArr[i] === 'c' || this.personTypeArr[i] === 'd' || this.personTypeArr[i] === 'e' || this.personTypeArr[i] === 'w') {
          if (age < 18) {
            this.$Modal.error({
              title: '数据保存失败',
              content: '主申请人需年满18周岁'
            })
          }
        }
      }
      let a = this.personTypeArr.indexOf('p', 0)
      let b = this.personTypeArr.indexOf('v', 0)
      let c = this.personTypeArr.indexOf('z', 0)
      console.log(a, b, c)
      if (a === -1 && b === -1 && c === -1) {
        this.$Modal.error({
          title: '数据保存失败',
          content: '请选择残疾人员或者非上述类别（必选一项）'
        })
        return
      }
      if (this.formDate.personList.length === 1) {
        if (age < 28) {
          this.$Modal.error({
            title: '数据保存失败',
            content: '主申请人需年满28周岁'
          })
          return false
        }
      } else if (this.formDate.personList.length > 1) {
        if (age < 18) {
          this.$Modal.error({
            title: '数据保存失败',
            content: '主申请人需年满18周岁'
          })
          return false
        }
      }
      // 判断申请人是否是单身(看家庭人口数)
      if (this.formDate.personList.length === 1) { // 单身
        if (parseInt(this.a) > parseInt(this.ruleData.singleGzfMoneyStandard) || parseInt(this.a) === parseInt(this.ruleData.singleGzfMoneyStandard)) {
          this.$Modal.error({
            title: '数据保存失败',
            content: '月收入超过单身公租房月收入标准,不符合申请规则'
          })
          return false
        }
      } else if (this.formDate.personList.length > 1) {
        console.log(this.formDate.rjysr, this.ruleData.gzfMoneyStandard)
        if (parseInt(this.a) > parseInt(this.ruleData.gzfMoneyStandard) || parseInt(this.a) === parseInt(this.ruleData.gzfMoneyStandard)) {
          this.$Modal.error({
            title: '数据保存失败',
            content: '月收入超过单身公租房月收入标准,不符合申请规则'
          })
          return false
        }
      }
      if (this.rjmj > parseInt(this.ruleData.areaStandard)) {
        this.$Modal.error({
          title: '数据保存失败',
          content: '人均建筑面积超过标准,不符合申请规则'
        })
        return false
      }
      this.formDate.familyMoneyDate = date2str(this.formDate.familyMoneyDate)
      this.formDate.acceptDate = date2str(this.formDate.acceptDate)
      this.$emit('ee')
    },
    getAge (IDCard) {
      var yearBirth = IDCard.substring(6, 10)
      var monthBirth = IDCard.substring(10, 12)
      var dayBirth = IDCard.substring(12, 14)
      var myDate = new Date()
      var monthNow = myDate.getMonth() + 1
      var dayNow = myDate.getDay()
      var age = myDate.getFullYear() - yearBirth
      if (monthNow < monthBirth || (monthNow === monthBirth && dayNow < dayBirth)) {
        age--
      }
      return age
    },
    proposerRule (company_code) {
      let data = {
        lawSectionCode: company_code,
        interface_code: 'fangchanju-qbxyjk',
        idCard: this.$route.params.cardno,
        code: this.aacode
      }
      ensureApply(data).then(res => {
        console.log(data)
        if (res.data.errcode === 0) {
          console.log(res.data.data, '规则信息')
          this.ruleData = res.data.data
          this.personType = res.data.data.personTypeList
          let obj = { 'personTypeCode': 'z', 'personTypeName': '非上述类别' }
          this.personType.push(obj)
          if (res.data.data.personTypeList !== undefined) {
            this.personTypeArr[0] = res.data.data.personTypeList[0].personTypeCode
            console.log(this.personTypeArr[0], '已选择申请人类型数据显示')
          } else {
            console.log('这是没有personTypeList')
          }
        } else {
          this.$Notice.error({ title: res.data.errmsg })
          console.log('接口调用失败')
        }
      })
    },
    checkAve () { // 计算家庭人均建筑面积
      var total = 0
      var number = this.rjmjArr.length
      for (var i = 0; i < this.rjmjArr.length; i++) {
        if (this.rjmjArr[i] === '') {
          this.rjmjArr.splice(i, i + 1)
        } else {
          total = total + parseInt(this.rjmjArr[i])
        }
      }
      if (number > 0) {
        this.rjmj = (total / number).toFixed(4)
      } else {
        this.rjmj = '0.0000'
      }
      this.formDate.buildAveArea = this.rjmj
    }
  }
}
</script>
